﻿namespace Common
{
    /// <summary>
    /// json lzy
    /// </summary>
    public class Context
    {
        public static void Write(System.Web.HttpContext context, string str)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(str);
            context.Response.Flush();
            //context.Response.Close();//若不去在网上chrome 不显示ashx
        }

        public static void Write(System.Web.HttpContext context, bool b)
        {
            string json = string.Format("flag:{0}", b ? "true" : "false");

            context.Response.ContentType = "text/plain";
            context.Response.Write(context.Request.QueryString["jsoncallback"] + "({" + json + "})");
            context.Response.Flush();
            //context.Response.Close();
        }

        public static void Write(System.Web.HttpContext context, bool b, string msg)
        {
            string json = string.Format("flag:{0},data:{1}", b ? "true" : "false",
                                        msg.IndexOfAny(new char[] { '{', '[' }) == 0 ? msg : string.Format("\"{0}\"", msg));

            context.Response.ContentType = "text/plain";
            context.Response.Write(context.Request.QueryString["jsoncallback"] + "({" + json + "})");
            context.Response.Flush();
            //context.Response.Close();
        }

    }
}
